import request from '@/utils/request'
const UpmsUserPermissionService = {
  state: {},

  mutations: {},

  actions: {
    // 获取指定用户下的权限
    getPermissionByUserId({ commit }, userId) {
      return new Promise((resolve, reject) => {
        request.get('userPermission/getPermissionByUserId', { userId: userId }).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },

    // 保存分配的权限
    userPermissionSave({ commit }, params) {
      return new Promise((resolve, reject) => {
        request.post(`userPermission/userPermissionSave/${params.userId}`, params.permissionIdList).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },

    // 删除分配的权限
    userPermissionRemove({ commit }, params) {
      return new Promise((resolve, reject) => {
        request.post(`userPermission/userPermissionRemove/${params.userId}`, params.permissionIdList).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default UpmsUserPermissionService
